<template>
	<tm-app ref="app">
		<tm-navbar title="开课维护" color="orange" linear="right" beforeBack="true" hideHome="true"></tm-navbar>
		
		
		<tm-sheet v-for="(item,index) in subjectlist" :key="index">
			<tm-text :font-size="30" _class="text-weight-b" :label="item.name"></tm-text>
			<tm-divider></tm-divider>
			<view class="flex-row flex flex-wrap">
				<view v-for="(item_a,index_a) in item.children" :key="index_a" class="flex-row flex flex-wrap">
					<tm-tag v-if="item_a.status" @click="mangBsSubject(item_a['id'])" color="orange" size="n" :label="item_a.name"></tm-tag>
					<tm-tag v-else checkable @click="mangBsSubject(item_a['id'])" color="orange" size="n" :label="item_a.name"></tm-tag>
					
					<view v-for="(item_b,index_b) in item_a.children" :key="index_b">
						<tm-tag v-if="item_b.status" @click="mangBsSubject(item_b['id'])" color="orange" size="n" :label="item_b.name"></tm-tag>
						<tm-tag v-else checkable @click="mangBsSubject(item_b['id'])" color="orange" size="n" :label="item_b.name"></tm-tag>
					</view>
				</view>
			</view>
		</tm-sheet>

		

	</tm-app>
</template>

<script lang="ts" setup>
	import { ref, nextTick } from "vue";
	import { onLoad } from "@dcloudio/uni-app";
	import { isPhone, isEmpty, isIdCard } from "@/tmui/tool/function/util";
	import { loadJcData , managerBsSubject } from '@/api/bsubject'


	const userid = ref('');
	const subjectlist = ref([]);
	const bssubjectlist = ref([]);
	
	
	onLoad(() => {
		userid.value = uni.getStorageSync("userid");
		console.log('初始化程序加载数据！', userid.value);
		if (isEmpty(userid.value)) {
			uni.redirectTo({
				url: '/pages/index/index' // 返回首页
			})
		} else {
			// entity.value.wxid = userid.value;
			loadSujectDetail();
		}
	})
	
	const mangBsSubject = async (subid : any) => {
		// console.log(subid);
		let param = { "userid": userid.value,"subid":subid };
		// console.log(JSON.stringify(param));
		const result = await managerBsSubject(param);
		console.log("结果：",result);
		loadSujectDetail();
	}


	// 加载科目的基础数据
	const loadSujectDetail = async () => {
		let param = { "userid": userid.value };
		const result = await loadJcData(param);
		console.log("结果：",result);
		subjectlist.value = result;
		// bssubjectlist.value = result.bsAllSubject;
	}
	
	
	
	
	
</script>


<style>

</style>
